import router from "./router";
import {useToken} from './stores/counter'
import nprogress  from 'nprogress'
import 'nprogress/nprogress.css'

const whileList = ['/login','/404']
router.beforeEach((to,from,next)=>{
    nprogress.start()
    const {getToken} =useToken()
    const token = getToken()
    // console.log(token);
    if(token){
        if(to.path==='/login'){
            next('/')
        }else{
            next()
        }
    }else{
        if(whileList.includes(to.path)){
            next()
        }else(
            next('/login')
        )
    }
})
router.afterEach(()=>{
    nprogress.done()
})